# -*- coding: utf-8 -*-
# @Time : 2022-01-08 17:58
# @Author : Z
# @Function :
import traceback

from Common.Excel.excel import get_reader, get_writer
from Keywords.web_keys import Web

web = Web()
# obj对象，行，行数
def web_excel(obj, line, i):
    # 分组模块不执行
    if len(line[0]) > 1 or len(line[1]) > 1:
        # print(line)
        pass
    # 获取关键字
    try:
        func = getattr(obj, line[3])
    except Exception as e:
        print("关键字不存在%s:" % line[3])
        return

    # 截取参数
    params = line[4:]
    params = params[:params.index('')]

    # 反射调用函数
    try:
        if params:
            func(*params)
        else:
            func()
        writer.write(i, 7, 'pass', 3)
    except Exception as e:
        writer.write(i, 7, 'fail', 2)
        writer.write(i, 8, str(traceback.format_exc()))


reader = get_reader('../../lib/web/电商后台用例.xlsx')
writer = get_writer('../../lib/web/电商后台用例.xlsx', '../../lib/web/result-电商后台用例.xlsx')

sheetname = reader.get_sheets()
for sheet in sheetname:
    reader.set_sheet(sheet)
    writer.set_sheet(sheet)
    lines = reader.readline()
    for i in range(1, len(lines)):
        line = lines[i]
        print(line)
        web_excel(web, line, i)
    print()

writer.save_close()
